import {wgs84togcj02} from '@/util/util.js';
export class Geolocation {
	constructor(){
		this.wid = null;
	}
	
	getCurrentPosition() {
		return new Promise((resolve, reject)=> {
			plus.geolocation.getCurrentPosition( p => {
					//let pos = wgs84togcj02(p.coords.longitude, p.coords.latitude);
					let pos = [p.coords.longitude, p.coords.latitude];
					resolve(pos);
				}, e =>{
					reject(e)
				},{
					enableHighAccuracy: true,
					timeout: 8000,
					provider:'amap',
					coordsType:'gcj02',
				}
			);
		})
	}
	
	watchPosition(cb){
		this.wid = plus.geolocation.watchPosition(
			(p) => {
				cb(p)
			},(e) => {
				console.log(e);
			}, {
				enableHighAccuracy: true,
				timeout: 8000,
				provider:'amap',
				coordsType:'gcj02',
			},
		);
	}
	
	clearWatch() {
		plus.geolocation.clearWatch(this.wid);
		this.wid = null;
	}
}